package com.matt.service.impl;

import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.exception.BusinessException;
import com.matt.domain.Classes;
import com.matt.domain.course.*;
import com.matt.domain.nursery.NurserySchedule;
import com.matt.domain.nursery.NurseryScheduleRecord;
import com.matt.domain.rel.RelTeacherCoursePlanAttended;
import com.matt.foundation.DO.AdviseDetailDO;
import com.matt.foundation.DO.TeacherDO;
import com.matt.foundation.DO.course.CoursePlanClassesDO;
import com.matt.foundation.constant.CourseConstant;
import com.matt.foundation.constant.NoticeMessageConstant;
import com.matt.foundation.query.ClassesCoursePlanQuery;
import com.matt.foundation.query.CoursePlanQuery;
import com.matt.foundation.query.FamilyCoursePlanQuery;
import com.matt.foundation.utils.DateUtil;
import com.matt.foundation.vo.course.PadCoursePlanDetailVo;
import com.matt.foundation.vo.course.PadTeacherCoursePlanListVo;
import com.matt.repository.ClassesRepository;
import com.matt.repository.NoticeMessageRepository;
import com.matt.repository.base.ClassesChildrenRepository;
import com.matt.repository.base.ClassesCoursePlanRepository;
import com.matt.repository.base.NurseryScheduleNativeRepository;
import com.matt.repository.course.*;
import com.matt.repository.nursery.NurseryScheduleRecordRepository;
import com.matt.repository.rel.RelTeacherCoursePlanNurseryRepository;
import com.matt.service.CourseNurseryService;
import com.matt.service.remoteCall.SsoCallService;
import com.matt.service.TeacherService;
import com.tuo51.foudation.utils.StaffDTOUtils;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.matt.foundation.model.ErrorCode.COURSE_PLAN_NURSERY_CANNOT_DELETE;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/3/13
 * *******************************
 */
@Slf4j
@Service
public class CourseNurseryServiceImpl implements CourseNurseryService {


    @Autowired
    private CoursePlanTopicRepository coursePlanTopicRepository;

    @Autowired
    private ClassesRepository classesRepository;

    @Autowired
    private ClassesChildrenRepository classesChildrenRepository;

    @Autowired
    private ClassesCoursePlanRepository classesCoursePlanRepository;

    @Autowired
    private CoursePlanClassesRepository coursePlanClassesRepository;


    @Autowired
    private PrepareCourseRepository prepareCourseRepository;


    @Autowired
    private RelTeacherCoursePlanNurseryRepository relTeacherCoursePlanNurseryRepository;

    @Autowired
    private CourseRepository courseRepository;

    @Autowired
    private SsoCallService ssoCallService;

    @Autowired
    private TeacherService teacherService;

    @Autowired
    private NoticeMessageRepository noticeMessageRepository;

    @Autowired
    private NurseryScheduleNativeRepository nurseryScheduleNativeRepository;

    @Autowired
    private NurseryScheduleRecordRepository nurseryScheduleRecordRepository;

    @Autowired
    private  ChildrenCourseItemRepository childrenCourseItemRepository;

    @Transactional
    @Override
    public Boolean createCourseForClasses(String classesId, String areaId, CourseTopic topic) {
        List<CoursePlanTopic> coursePlanNurseryList = coursePlanTopicRepository.findByTopicIdAndCourseDateAfter(topic.getId(), new Date());
        List<CoursePlanClasses> nurseryClassesList = Lists.newArrayList();
        for (CoursePlanTopic planTopic : coursePlanNurseryList) {
            CoursePlanClasses coursePlanClasses = CoursePlanClasses.ofTopic(planTopic, classesId, areaId);
            nurseryClassesList.add(coursePlanClasses);
        }
        coursePlanClassesRepository.saveAll(nurseryClassesList);
        return true;
    }


    @Override
    public Page<PadTeacherCoursePlanListVo> getPadCoursePlanList(ClassesCoursePlanQuery query, Boolean isTestUser) {
        if (isTestUser){
            //外部用户，只返回前10条数据
            query.setPageNum(0);
            query.setPageSize(10);
        }
        String today = DateUtil.millisToDateTime(System.currentTimeMillis(), "yyyy-MM-dd");
        query.setBeginDate(today);
        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        List<CoursePlanClassesDO> classesPlanList = classesCoursePlanRepository.findByConditions(query);
        List<PadTeacherCoursePlanListVo> voList = classesPlanList.stream().map(o->PadTeacherCoursePlanListVo.of(o, Lists.newArrayList())).collect(Collectors.toList());
        if(isTestUser){
            //重新设置count
            return new PageImpl<>(voList,PageRequest.of(query.getPageNum(),query.getPageSize()),voList.size());
        }
        Long count = classesCoursePlanRepository.countHistoryByCondition(query);
        return new PageImpl(voList, PageRequest.of(query.getPageNum(), query.getPageSize()), count);
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getPadCoursePlanHistory(ClassesCoursePlanQuery query, Boolean isTestUser) {
        if (isTestUser){
            //外部用户，只返回前10条数据
            query.setPageNum(0);
            query.setPageSize(10);
        }
        String today = DateUtil.millisToDateTime(System.currentTimeMillis(), "yyyy-MM-dd");
        query.setEndDate(today);
        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        List<CoursePlanClassesDO> classesPlanList = classesCoursePlanRepository.findHistoryByCondition(query);
        List<PadTeacherCoursePlanListVo> voList = classesPlanList.stream().map(o->PadTeacherCoursePlanListVo.of(o, Lists.newArrayList())).collect(Collectors.toList());;
        if(isTestUser){
            //重新设置count
            return new PageImpl<>(voList,PageRequest.of(query.getPageNum(),query.getPageSize()),voList.size());
        }
        Long count = classesCoursePlanRepository.countHistoryByCondition(query);
        return new PageImpl(voList, PageRequest.of(query.getPageNum(), query.getPageSize()), count);
    }


    @Override
    public PadCoursePlanDetailVo getPadCoursePlanDetail(String classesCoursePlanId) {
        CoursePlanClasses coursePlanClasses = coursePlanClassesRepository.getOne(classesCoursePlanId);
        Course course = courseRepository.getOne(coursePlanClasses.getCourseId());
        CoursePlanTopic coursePlanTopic=new CoursePlanTopic();
        if(coursePlanClasses.getCoursePlanTopicId()==""||Objects.isNull(coursePlanClasses.getCoursePlanTopicId())){
        	coursePlanTopic.setTopicName("");
        }else{
        	 coursePlanTopic = coursePlanTopicRepository.getOne(coursePlanClasses.getCoursePlanTopicId());
             if(Objects.isNull(coursePlanTopic)){
             	coursePlanTopic.setTopicName("");
             }
        }

        List<AdviseDetailDO> adviseList = classesChildrenRepository.findAdviseByClasses(coursePlanClasses.getClassesId());//查询班级孩子的建议
        List<TeacherDO> teacherList = teacherService.getTeacherByClasses(coursePlanClasses.getClassesId());//查询班级老师


        Classes classes = classesRepository.getOne(coursePlanClasses.getClassesId());
        PrepareCourse prepareCourse = prepareCourseRepository.findByCoursePlanClassesId(coursePlanClasses.getId());//查询排课的备课情况

//        CourseTemplate1 courseTemplate1 = courseTemplate1Repository.getOne(course.getCourseTemplateId());//托班课程 官方模板
//
        Object template = null;
//        if (Objects.nonNull(prepareCourse) && CourseConstant.PrepareStatus.PREPARED.codeOf() == coursePlanClasses.getPrepareStatus() || CourseConstant.PrepareStatus.APPROVED.codeOf() == coursePlanClasses.getPrepareStatus()){ //有备课记录且排课的备课状态是 已备课或已通过
//            PrepareTemplate1 prepareTemplate1 = prepareTemplate1Repository.findByPrepareCourseId(prepareCourse.getId());
//            template = PadCourseTemplate1Vo.ofPrepareCourse(prepareCourse, prepareTemplate1, coursePlanTopic.getTopicName());
//        } else
//            template =  PadCourseTemplate1Vo.ofCourse(coursePlanClasses, courseTemplate1, coursePlanTopic.getTopicName());//用官方模板来返回

        PadCoursePlanDetailVo vo = PadCoursePlanDetailVo.ofNursery(course.getTemplateType(), coursePlanClasses, adviseList, teacherList,
                template, classes.getName(), coursePlanTopic.getTopicName());
        return vo;
    }


    @Transactional
    @Override
    public CoursePlanClasses beginCourse(String classesCoursePlanId, String[] teacherIds, String staffId, String ticket) {
        CoursePlanClasses classesCoursePlan = coursePlanClassesRepository.getOne(classesCoursePlanId);
        classesCoursePlan.setCourseStatus(CourseConstant.CourseStatus.PROCESSED.codeOf());
        classesCoursePlan.setBeginCourseTeacherId(staffId);
        classesCoursePlan.setBeginCourseTime(new Date());
        coursePlanClassesRepository.save(classesCoursePlan);
        List<RelTeacherCoursePlanAttended> teacherCoursePlanNurseryList = Lists.newArrayList();
        for (String id : teacherIds) {
            List<StaffDTO> staffDTOList = ssoCallService.getStaffDTOList(null, teacherIds);
            teacherCoursePlanNurseryList.add(RelTeacherCoursePlanAttended.of(id, classesCoursePlan.getId(), StaffDTOUtils.matchOf(id, staffDTOList).getRealName()));
        }
        relTeacherCoursePlanNurseryRepository.saveAll(teacherCoursePlanNurseryList);//关联老师和排课记录
        teacherService.precessCourse(classesCoursePlanId);//关联历史
        return classesCoursePlan;
    }


    @Transactional
    @Override
    public Boolean delete(String planTopicId) {
        List<CoursePlanClasses> planClasses = coursePlanClassesRepository.findByCoursePlanTopicId(planTopicId);
        planClasses.forEach(o -> {
            if (o.getPrepareStatus() != CourseConstant.PrepareStatus.NON_PREPARE.codeOf() || o.getCourseStatus() != CourseConstant.CourseStatus.STARTING.codeOf())
                throw new BusinessException(COURSE_PLAN_NURSERY_CANNOT_DELETE, "该课程已经有班级备课，或者上了，无法进行删除");
            noticeMessageRepository.deleteByLinkIdAndCategoryIn(o.getId(), com.google.common.collect.Lists.newArrayList(NoticeMessageConstant.Category.THEME_COURSE_PREPARE.codeOf(), NoticeMessageConstant.Category.THEME_COURSE_AUDIT.codeOf(), NoticeMessageConstant.Category.THEME_COURSE_REJECTED.codeOf()));
        });
        coursePlanTopicRepository.deleteById(planTopicId);
        coursePlanClassesRepository.deleteByCoursePlanTopicId(planTopicId);

        return true;
    }



    @Transactional
    @Override
    public Boolean systemProcessCourse(Date date) {
        // 不再需要定时任务处理主题课程
//        String preDay = DateUtil.millisToDateTime(DateUtil.plusDays(date.getTime(), -1L), "yyyy-MM-dd");
//        List<NonProcessCourseClassesDO> courseClassesDOList = classesCoursePlanRepository.findByCourseDateAndCourseStatus(preDay, CourseNurseryConstant.CourseStatus.STARTING.codeOf());
//        for (NonProcessCourseClassesDO courseClasses : courseClassesDOList) {
//            coursePlanClassesRepository.updateCourseStatusById(CourseNurseryConstant.CourseStatus.NO_PROCESS.codeOf(), courseClasses.getCoursePlanClassesId());
//            //处理老师历史课程表
//            teacherService.precessCourse(courseClasses.getCoursePlanClassesId());
//        }
        return true;
    }

    @Override
    public long getEarlyAndNurseryAllCount(CoursePlanQuery query) {
        long earlyAndNurseryAllCount = classesCoursePlanRepository.getEarlyAndNurseryAllCount(query);
        return earlyAndNurseryAllCount;
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getPadTodayCoursePlanList(ClassesCoursePlanQuery query, Boolean isTestUser,String type, Boolean isAll) {

        if ("today".equals(type)) {
            //今日
            String today = DateUtil.millisToDateTime(System.currentTimeMillis(), "yyyy-MM-dd");
            query.setBeginDate(today);
            query.setEndDate(today);
        } else if ("week".equals(type)) {
            //查询本周课程列表
            String weekStartDay = DateUtil.getWeekStartDay();
            String weekEndDay = DateUtil.getWeekEndDay();
            query.setBeginDate(weekStartDay);
            query.setEndDate(weekEndDay);
        } else if ("nextweek".equals(type)) {
            //查询下周课程列表
            String weekStartDay = DateUtil.formatDayToStr(DateUtil.getBeginDayOfNextWeek());
            String weekEndDay = DateUtil.formatDayToStr(DateUtil.getEndDayOfNextWeek());
            query.setBeginDate(weekStartDay);
            query.setEndDate(weekEndDay);
        }
        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        Classes classes = classesRepository.getOne(query.getClassId());
        //查询当天排课信息
        List<NurserySchedule>  nurseryScheduleList  = nurseryScheduleNativeRepository.findScheduleClassIdByLessonDate(query.getBeginDate(),query.getEndDate(),query.getClassId());
        if (nurseryScheduleList.size()== 0){
            return  new PageImpl(new ArrayList(), PageRequest.of(query.getPageNum(), query.getPageSize()),0);
        }
        Pageable pageable = PageRequest.of(query.getPageNum(), query.getPageSize());
        //排课信息
        Page<NurseryScheduleRecord>  nurseryScheduleRecordList = nurseryScheduleRecordRepository.findByNurseryScheduleId(nurseryScheduleList.get(0).getId(),pageable);

        if (isAll || "nextweek".equals(type) || "week".equals(type)){
            List<String> stringList = nurseryScheduleList.stream().map(k->k.getId()).collect(Collectors.toList());
            String[] ids = stringList.toArray(new String[stringList.size()]);
            nurseryScheduleRecordList =  nurseryScheduleRecordRepository.findByCategoryAndNurseryScheduleIdIn(1,ids,pageable);
        }
        List<PadTeacherCoursePlanListVo> listVos = new ArrayList<>();
        for (int i = 0; i < nurseryScheduleRecordList.getContent().size(); i++) {
            PadTeacherCoursePlanListVo padTeacherCoursePlanListVo = new PadTeacherCoursePlanListVo();
            padTeacherCoursePlanListVo.setCourseName(nurseryScheduleRecordList.getContent().get(i).getActivityContent());
            padTeacherCoursePlanListVo.setCourseType(CourseConstant.Category.NURSERY.codeOf());
            padTeacherCoursePlanListVo.setTypeName(CourseConstant.Category.NURSERY.valueOf());
            padTeacherCoursePlanListVo.setCourseDate(nurseryScheduleRecordList.getContent().get(i).getBeginDate());
            padTeacherCoursePlanListVo.setBeginTime(nurseryScheduleRecordList.getContent().get(i).getBeginDate());
            padTeacherCoursePlanListVo.setEndTime(nurseryScheduleRecordList.getContent().get(i).getEndDate());
//            padTeacherCoursePlanListVo.setCourseStatus(1);
            padTeacherCoursePlanListVo.setClassesName(classes.getName());
            padTeacherCoursePlanListVo.setCategory(nurseryScheduleRecordList.getContent().get(i).getCategory());
            padTeacherCoursePlanListVo.setResObj(nurseryScheduleRecordList.getContent().get(i).getResObj());
            listVos.add(padTeacherCoursePlanListVo);
        }
        return new PageImpl(listVos, PageRequest.of(query.getPageNum(), query.getPageSize()), listVos.size());
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getPadFamilyTodayCoursePlanList(FamilyCoursePlanQuery query , String type, Boolean isAll) {
        if ("today".equals(type)) {
            //今日
            String today = DateUtil.millisToDateTime(System.currentTimeMillis(), "yyyy-MM-dd");
            query.setBeginDate(today);
            query.setEndDate(today);
        } else if ("week".equals(type)) {
            //查询本周课程列表
            String weekStartDay = DateUtil.getWeekStartDay();
            String weekEndDay = DateUtil.getWeekEndDay();
            query.setBeginDate(weekStartDay);
            query.setEndDate(weekEndDay);
        } else if ("nextweek".equals(type)) {
            //查询下周课程列表
            String weekStartDay = DateUtil.formatDayToStr(DateUtil.getBeginDayOfNextWeek());
            String weekEndDay = DateUtil.formatDayToStr(DateUtil.getEndDayOfNextWeek());
            query.setBeginDate(weekStartDay);
            query.setEndDate(weekEndDay);
        }

        //查询当天排课信息
        List<NurserySchedule>  nurseryScheduleList  = nurseryScheduleNativeRepository.findScheduleByChildrenIdAndLessonDate(query.getChildrenId(),query.getBeginDate(),query.getEndDate());
        if (nurseryScheduleList.size()== 0){
            return  new PageImpl(new ArrayList(), PageRequest.of(query.getPageNum(), query.getPageSize()),0);
        }
        Pageable pageable = PageRequest.of(query.getPageNum(), query.getPageSize());
        //排课信息
        Page<NurseryScheduleRecord>  nurseryScheduleRecordList = nurseryScheduleRecordRepository.findByNurseryScheduleId(nurseryScheduleList.get(0).getId(),pageable);

        if (isAll || "nextweek".equals(type) || "week".equals(type)){
            List<String> stringList = nurseryScheduleList.stream().map(k->k.getId()).collect(Collectors.toList());
            String[] ids = stringList.toArray(new String[stringList.size()]);
            Integer[] categorys = new Integer[]{1,3};
            nurseryScheduleRecordList =  nurseryScheduleRecordRepository.findByCategoryInAndNurseryScheduleIdIn(categorys,ids,pageable);
        }
        List<PadTeacherCoursePlanListVo> listVos = new ArrayList<>();
        for (int i = 0; i < nurseryScheduleRecordList.getContent().size(); i++) {
            PadTeacherCoursePlanListVo padTeacherCoursePlanListVo = new PadTeacherCoursePlanListVo();
            padTeacherCoursePlanListVo.setCourseName(nurseryScheduleRecordList.getContent().get(i).getActivityContent());
            padTeacherCoursePlanListVo.setCourseDate(nurseryScheduleRecordList.getContent().get(i).getBeginDate());
            padTeacherCoursePlanListVo.setBeginTime(nurseryScheduleRecordList.getContent().get(i).getBeginDate());
            padTeacherCoursePlanListVo.setEndTime(nurseryScheduleRecordList.getContent().get(i).getEndDate());
            padTeacherCoursePlanListVo.setCategory(nurseryScheduleRecordList.getContent().get(i).getCategory());
            padTeacherCoursePlanListVo.setResObj(nurseryScheduleRecordList.getContent().get(i).getResObj());
            listVos.add(padTeacherCoursePlanListVo);
        }
        return new PageImpl(listVos, PageRequest.of(query.getPageNum(), query.getPageSize()), listVos.size());
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getTodayCourse(ClassesCoursePlanQuery query, Boolean isTestUser) {
        return null;
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getPadWeekCoursePlanList(ClassesCoursePlanQuery query, Boolean isTestUser) {
        if (isTestUser){
            //外部用户，只返回前10条数据
            query.setPageNum(0);
            query.setPageSize(10);
        }
        String weekStartDay = DateUtil.getWeekStartDay();
        String weekEndDay = DateUtil.getWeekEndDay();
        query.setBeginDate(weekStartDay);
        query.setEndDate(weekEndDay);


        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        List<CoursePlanClassesDO> classesPlanList = classesCoursePlanRepository.findWeekCourseByConditions(query);
        List<PadTeacherCoursePlanListVo> voList = classesPlanList.stream().map(o->PadTeacherCoursePlanListVo.of(o, Lists.newArrayList())).collect(Collectors.toList());
  /*      if(isTestUser){
            //重新设置count
            return new PageImpl<>(voList,PageRequest.of(query.getPageNum(),query.getPageSize()),voList.size());
        }*/
        //  Long count = classesCoursePlanRepository.countHistoryByCondition(query);
        return new PageImpl(voList, PageRequest.of(query.getPageNum(), query.getPageSize()), voList.size());
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getPadCourseByNextWeekPlanList(ClassesCoursePlanQuery query, Boolean isTestUser) {
        if (isTestUser){
            //外部用户，只返回前10条数据
            query.setPageNum(0);
            query.setPageSize(10);
        }
        String weekStartDay = DateUtil.formatDayToStr(DateUtil.getBeginDayOfNextWeek());
        String weekEndDay = DateUtil.formatDayToStr(DateUtil.getEndDayOfNextWeek());
        query.setBeginDate(weekStartDay);
        query.setEndDate(weekEndDay);


        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        List<CoursePlanClassesDO> classesPlanList = classesCoursePlanRepository.findWeekCourseByConditions(query);
        List<PadTeacherCoursePlanListVo> voList = classesPlanList.stream().map(o->PadTeacherCoursePlanListVo.of(o, Lists.newArrayList())).collect(Collectors.toList());
        return new PageImpl(voList, PageRequest.of(query.getPageNum(), query.getPageSize()), voList.size());
    }
    
    @Override
    public Page<PadTeacherCoursePlanListVo> getPadKXTodayCoursePlanList(ClassesCoursePlanQuery query, Boolean isTestUser) {
       /* if (isTestUser){
            //外部用户，只返回前10条数据
            query.setPageNum(0);
            query.setPageSize(10);
        }*/
        String today = DateUtil.millisToDateTime(System.currentTimeMillis(), "yyyy-MM-dd");
        query.setBeginDate(today);
        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        List<CoursePlanClassesDO> classesPlanList = classesCoursePlanRepository.findKXTodayCourseByConditions(query);
        List<PadTeacherCoursePlanListVo> voList = classesPlanList.stream().map(o->PadTeacherCoursePlanListVo.of(o, Lists.newArrayList())).collect(Collectors.toList());
  /*      if(isTestUser){
            //重新设置count
            return new PageImpl<>(voList,PageRequest.of(query.getPageNum(),query.getPageSize()),voList.size());
        }*/
      //  Long count = classesCoursePlanRepository.countHistoryByCondition(query);
        return new PageImpl(voList, PageRequest.of(query.getPageNum(), query.getPageSize()), voList.size());
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getPadKXWeekCoursePlanList(ClassesCoursePlanQuery query, Boolean isTestUser) {
        if (isTestUser){
            //外部用户，只返回前10条数据
            query.setPageNum(0);
            query.setPageSize(10);
        }
        String weekStartDay = DateUtil.getWeekStartDay();
        String weekEndDay = DateUtil.getWeekEndDay();
        query.setBeginDate(weekStartDay);
        query.setEndDate(weekEndDay);


        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        List<CoursePlanClassesDO> classesPlanList = classesCoursePlanRepository.findKXWeekCourseByConditions(query);
        List<PadTeacherCoursePlanListVo> voList = classesPlanList.stream().map(o->PadTeacherCoursePlanListVo.of(o, Lists.newArrayList())).collect(Collectors.toList());
  /*      if(isTestUser){
            //重新设置count
            return new PageImpl<>(voList,PageRequest.of(query.getPageNum(),query.getPageSize()),voList.size());
        }*/
        //  Long count = classesCoursePlanRepository.countHistoryByCondition(query);
        return new PageImpl(voList, PageRequest.of(query.getPageNum(), query.getPageSize()), voList.size());
    }

    @Override
    public Page<PadTeacherCoursePlanListVo> getPadKXCourseByNextWeekPlanList(ClassesCoursePlanQuery query, Boolean isTestUser) {
        if (isTestUser){
            //外部用户，只返回前10条数据
            query.setPageNum(0);
            query.setPageSize(10);
        }
        String weekStartDay = DateUtil.formatDayToStr(DateUtil.getBeginDayOfNextWeek());
        String weekEndDay = DateUtil.formatDayToStr(DateUtil.getEndDayOfNextWeek());
        query.setBeginDate(weekStartDay);
        query.setEndDate(weekEndDay);


        query.setCourseCategory(CourseConstant.Category.NURSERY.codeOf());
        List<CoursePlanClassesDO> classesPlanList = classesCoursePlanRepository.findKXWeekCourseByConditions(query);
        List<PadTeacherCoursePlanListVo> voList = classesPlanList.stream().map(o->PadTeacherCoursePlanListVo.of(o, Lists.newArrayList())).collect(Collectors.toList());
        return new PageImpl(voList, PageRequest.of(query.getPageNum(), query.getPageSize()), voList.size());
    }
}
